// FormAddin.h : Declaration of the CFormAddin
#ifndef FORM_ADDIN_H
#define FORM_ADDIN_H

#pragma once
#include "resource.h"       // main symbols



#include "OutlookAddin_i.h"
#include "SettingForm.h"
#include "SendForm.h"


#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

using namespace ATL;


extern _ATL_FUNC_INFO OnClickSettingButtonInfo;
extern _ATL_FUNC_INFO OnClickSendButtonInfo;
// CFormAddin

class ATL_NO_VTABLE CFormAddin :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CFormAddin, &CLSID_FormAddin>,
	public IDispatchImpl<IFormAddin, &IID_IFormAddin, &LIBID_OutlookAddinLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
	public IDispatchImpl<_IDTExtensibility2, &__uuidof(_IDTExtensibility2), &LIBID_AddInDesignerObjects, /* wMajor = */ 1>,
	public IDispEventSimpleImpl<1,CFormAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
	public IDispEventSimpleImpl<2,CFormAddin,&__uuidof(Office::_CommandBarButtonEvents)>
	//public IDispEventSimpleImpl<2,CFormAddin,&__uuidof(Outlook::ApplicationEvents)>
{
public:
	Outlook::_ApplicationPtr spAppCache;
	CFormAddin()
	{
		spSettingForm = NULL;
		spSendForm = NULL;
	}

	DECLARE_REGISTRY_RESOURCEID(IDR_FORMADDIN)


	BEGIN_COM_MAP(CFormAddin)
		COM_INTERFACE_ENTRY(IFormAddin)
		COM_INTERFACE_ENTRY2(IDispatch, _IDTExtensibility2)
		COM_INTERFACE_ENTRY(_IDTExtensibility2)
	END_COM_MAP()

	BEGIN_SINK_MAP(CFormAddin)
		SINK_ENTRY_INFO(1, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickSettingButton, &OnClickSettingButtonInfo)
		SINK_ENTRY_INFO(2, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickSendButton, &OnClickSendButtonInfo)
		//SINK_ENTRY_INFO(2,__uuidof(Outlook::ApplicationEvents),/*dispid*/0xf005,OnOptionsAddPages,&OnOptionsAddPagesInfo)
	END_SINK_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
		if(spSettingForm)
			delete spSettingForm;
		if(spSendForm)
			delete spSendForm;
	}

public:

	void __stdcall OnClickSettingButton(IDispatch* Ctrl, VARIANT_BOOL* CancelDefault);
	void __stdcall OnClickSendButton(IDispatch* Ctrl, VARIANT_BOOL* CancelDefault);


	// _IDTExtensibility2 Methods
public:
	STDMETHOD(OnConnection)(LPDISPATCH Application, ext_ConnectMode ConnectMode, LPDISPATCH AddInInst, SAFEARRAY * * custom);
	STDMETHOD(OnDisconnection)(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom);
	STDMETHOD(OnAddInsUpdate)(SAFEARRAY * * custom);
	STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom);
	STDMETHOD(OnBeginShutdown)(SAFEARRAY * * custom);

private:
	Office::_CommandBarButtonPtr spButtonSetting;
	Office::_CommandBarButtonPtr spButtonSend;
	CSettingForm* spSettingForm;
	CSendForm* spSendForm;
};

OBJECT_ENTRY_AUTO(__uuidof(FormAddin), CFormAddin)
	

#endif